package com.dailyblue.java.net.tcp.demo1;

import lombok.SneakyThrows;

import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    @SneakyThrows
    public static void main(String[] args) {
        // 创建服务器并指定端口号
        ServerSocket ss = new ServerSocket(9999);
        System.out.println("服务器启动成功!");
        // 产生服务端的套接字,通过客户端来产生的
        Socket socket = ss.accept();
        System.out.println("服务器套接字产生成功");
        // 假设服务器负责接收
        InputStream in = socket.getInputStream();
        byte[] bytes = new byte[20];
        int len = in.read(bytes);
        String str = new String(bytes, 0, len);
        System.out.println("客户端：" + str);
        in.close();
        socket.close();
    }
}
